<template>
<div class="container">
  <div class="login-right" style="margin-top:10%;">
    <form autocomplete="off">
      <div class="login-main-form">
        <div class="login-input padding-top-10">
          <label>新密码</label>
          <el-input v-model="first" placeholder="请输入新密码" type="password" clearable></el-input>
        </div>
        <div class="login-input padding-top-20">
          <label>再次确认密码</label>
          <el-input v-model="confirm" placeholder="请再次确认密码" type="password" clearable></el-input>
        </div>
        <el-button
          class="login-button"
          type="primary"
          size="large"
          @click="submit"
        >确认</el-button>
      </div>
    </form>
  </div>
</div>
</template>

<script>
export default {
  data() {
    return {
      first: "",
      confirm: ""
    };
  },
  methods: {
    submit() {
      if(!this.first){
        this.$message({
          message:'请输入密码',
          type:'warning'
        })
        return
      }
      if(!this.confirm){
        this.$message({
          message:'请输入确认密码',
          type:'warning'
        })
        return
      }
      if(this.first!=this.confirm){
        this.$message({
          message:'密码不一致',
          type:'warning'
        })
        return
      }
      if(!this.$utils.identifyPwd(this.first)){
        this.$message({
          message:'密码长度为5~16，英文数字下划线',
          type:'warning'
        })
        return
      }
      this.resetKey=this.$utils.getParam('k')//获取url带的参数
      this.resetToken1=this.$utils.getParam('t1')
      this.resetToken2=this.$utils.getParam('t2')
      this.$postStream('/admin/auth/auhtUser/reset.do',{
        data:{
          newPasswd:this.first,
          resetKey:this.resetKey,
          resetToken1:this.resetToken1,
          resetToken2:this.resetToken2
        },
        success:(res)=>{
          if(res.success){
            this.$message.success('修改成功')
            setTimeout(function() {
              window.location.href = "login.html";
            }, 1000);
          }else{
            this.$message.error('修改失败')
          }
        },
        error:()=>{
          this.$message.error('修改失败')
        }
      })
    }
  }
};
</script>
<style lang="scss" scoped>
.resetForm {
  width: 40%;
  height: 100%;
  margin: 0px auto;
  text-align: center;
  display: flex;
  justify-content: center;
  flex-direction: column;
}
.login-right {
  width: 423px;
  height: auto;
  margin:0 auto;
  button {
    width: 100%;
  }
  label {
    display: block;
    line-height: 20px;
    height: 20px;
    margin-bottom: 10px;
    font-size:14px;
    font-weight: normal;
  }
}
.login-input {
  margin: 20px 0;
}
.container{
  width:100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
</style>
